473,426 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 software developers and data experts.

center a css popup in the browser using javascript

5
What I'm trying to do is to display a loading screen while an ajax request executes. I have a page that is fairly long with several tables worth of data and the sorting/pagination of each table is handled by ajax requests.

I'd like to have a css div that is displayed in the center of the browser window when a user selects an operation that kicks off an ajax request.

What I have thus far is a div that shows up in the center of the "unscrolled" browser window when needed (by unscrolled I mean that if the user were to first hit the page and activate a link in the visible portion of the page - not one found via scrolling down - the div would appear centered in that visible area). The problem that I'm having is that, if the user scrolls down and selects a link the kicks off a request, the div still appears centered on the "top" portion of the page (the original, "unscrolled" portion). I want the pop up div to be displayed in the center of the "visible" area of the browser. Here's the javascript I have thus far:

Expand|Select|Wrap|Line Numbers
  1. function showIndicator(){
  2.     var availHeight;
  3.     var availWidth;
  4.  
  5.     if(typeof(window.innerWidth) == 'number'){
  6.         availHeight = window.innerHeight;
  7.         availWidth = window.innerWidth;
  8.     }else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
  9.         availHeight = document.documentElement.clientHeight;
  10.         availWidth = document.documentElement.clientWidth;
  11.     }else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
  12.         availHeight = document.body.clientHeight;
  13.         availWidth = document.body.clientWidth;
  14.     }
  15.  
  16.     var indicatorWidth = 50;
  17.     var indicatorHeight = 50;
  18.     var left = (availWidth/2) - (indicatorWidth/2);
  19.     var top = (availHeight/2) - (indicatorHeight/2);
  20.     var indicator = document.getElementById('indicator');
  21.     indicator.style.border="1px solid gray";
  22.     indicator.style.background="white";
  23.     indicator.style.position="absolute";
  24.     indicator.style.zIndex="999";
  25.     indicator.style.top=top+"px";
  26.     indicator.style.left=left+"px";
  27.     indicator.style.display="block";
  28. }
  29.  
I hope I was able to convey my intent and my problem - I'm quite new to javascript/dhtml/ajax so I'm mainly hacking away in the dark here.
-I've only tested this in firefox 2 and ie 6 thus far.
Thanks very much!
Apr 2 '07 #1
4 17759
cmo
5
well, ended up figuring this one out after some more hacking,
added the following:
Expand|Select|Wrap|Line Numbers
  1. var yOffset
  2. if (self.pageYOffset){// all except Explorer
  3.     yOffset = self.pageYOffset;
  4. }
  5. else if (document.documentElement && document.documentElement.scrollTop)// Explorer 6 Strict{
  6.     yOffset = document.documentElement.scrollTop;
  7. }
  8. else if (document.body){ // all other Explorers
  9.     y = document.body.scrollTop;
  10. }
  11. ...
  12. var top = ((availHeight/2)+yOffset) - (indicatorHeight/2);
  13. ...
  14.  
and that seems to work just fine.
Apr 2 '07 #2
well, ended up figuring this one out after some more hacking,
added the following:
Expand|Select|Wrap|Line Numbers
  1. var yOffset
  2. if (self.pageYOffset){// all except Explorer
  3.     yOffset = self.pageYOffset;
  4. }
  5. else if (document.documentElement && document.documentElement.scrollTop)// Explorer 6 Strict{
  6.     yOffset = document.documentElement.scrollTop;
  7. }
  8. else if (document.body){ // all other Explorers
  9.     y = document.body.scrollTop;
  10. }
  11. ...
  12. var top = ((availHeight/2)+yOffset) - (indicatorHeight/2);
  13. ...
  14.  
and that seems to work just fine.
I was doing more or less that some days ago
The code i used was something like

Expand|Select|Wrap|Line Numbers
  1. var x = self.pageYOffset ? self.pageXOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollLeft : document.body ? document.body.scrollLeft : null;
  2.  
  3. var y = self.pageYOffset ? self.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body ? document.body.scrollTop : null;
  4.  
Apr 3 '07 #3
Hai im looking for a css inner popup that need to be place along to the window adjustments,

for example : when we right click the mouse on screen where ever the mouse pointer is there option will display accourding to that.

look at this code and position the displaying popup according to the button click

[HTML]<html>
<head>
<title>Inner Popup using CSS</title>
<style type="text/css">
.popup
{
position:absolute; left:0; top:0; width:400px;
border-style:solid;
border-width:1px;
border-color:blue;
background-color:yellow;
padding:5px;
color:red;
font-family:Arial;
font-weight:bold;
font-size:10pt;
z-index:2;
visibility:hidden;
}
</style>
<script language="JavaScript">
function ShowPop(id)
{
document.getElementById(id).style.visibility = "visible";
}
function HidePop(id)
{
document.getElementById(id).style.visibility = "hidden";
}
</script>
</head>
<body>
<table width="100%" class="frm" border=1>
<tr colspan=3>Inner POPUp using CSS
</tr>
<tr>
<td>
<span style="position:relative; background-color:#33d;">
<span id="example" class="popup">
<pre>&lt;script language="JavaScript"&gt;
function ShowPop(id)
{
document.getElementById(id).style.visibility = "visible";
}
function HidePop(id)
{
document.getElementById(id).style.visibility = "hidden";
}
&lt;/script&gt;
<input id="butt" type="button" onClick="HidePop('example');" value="Close" /></pre>
</span>
<input id="butt" type="button" onClick="javascript:void(0);ShowPop('example');" value="click"/></span>
</td>
<td>
<span style="position:relative; background-color:#33d;">
<span id="example" class="popup">
<pre>&lt;script language="JavaScript"&gt;
function ShowPop(id)
{
document.getElementById(id).style.visibility = "visible";
}
function HidePop(id)
{
document.getElementById(id).style.visibility = "hidden";
}
&lt;/script&gt;
<input id="butt" type="button" onClick="HidePop('example');" value="Close" /></pre>
</span>
<input id="butt" type="button" onClick="javascript:void(0);ShowPop('example');" value="Click" /></span>
</td><td>
<span style="position:relative; background-color:#33d;">
<span id="example" class="popup">
<pre>&lt;script language="JavaScript"&gt;
function ShowPop(id)
{
document.getElementById(id).style.visibility = "visible";
}
function HidePop(id)
{
document.getElementById(id).style.visibility = "hidden";
}
&lt;/script&gt;
<input id="butt" type="button" onClick="HidePop('example');" value="Close" /></pre>
</span>
<input id="butt" type="button" onClick="javascript:void(0);ShowPop('example');" value="Click" /></span>
</td>
</tr>
</table>
</body>
</html>[/HTML]

plz find the solution for this, i have to give this to my programmers, who are not able to fix this
Jan 9 '08 #4
acoder
16,027 Expert Mod 8TB
See if you find this article useful.
Jan 10 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Rob V | last post by:
I was wondering whether there was any way of loading an executable or windows shortcut from within a browser using Javascript or something similar. This is for use in an active desktop html file...
1
by: anonieko | last post by:
> Use x = window.Open(...) x.document.write( yourhtml) > How to print from javascript using .print > How to use ContentWindow > > How t use getElementById > How to get HTML of document...
3
by: anthonybrough | last post by:
I have an asp page that has a form to collect user data in a form. when the user clicks submit the input is validated. If any fields are not acceptable the user clicks on a button to go back to...
1
by: webpearl | last post by:
Welcome to all who r helping and sharing their ideas with others.i am a new to this forum.Can any one say an immediate soln on my questions: Qn1: How can i print a hidden data in the hidden data...
1
by: sundarachaitanyam | last post by:
hi, I am just wondering how to create a modal popup using javascript. The popup window shouldnt contain minimize,close and maximize buttons and it should be resizable? I am trying using...
4
by: Nuno | last post by:
Hello, I'm trying to call some web services only using javascript from a html page. I succeeded on doind this in IE with the use of the behavior:url(webservice.htc); (technique founded in the...
4
by: Rakhi | last post by:
hello i want to alter the download settings of mozilla firefox browser using javascript of my application !! wat is happenin in my application is, on calling a method , it make a file ready...
2
by: trivenisri | last post by:
Hi, I am triveni.Can any one know about 'How to open a MS Word document from Javascript in mozilla browser'.I am able to open in IE.Please help me about this issue. Regards, Triveni
1
by: shyamjumberi | last post by:
Hi, I am developing web application.using struts .I want the javascript code for getting the previous URL of the browser. any body help me.
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.